
import axios from '~/axios'
import { joinPramas } from './manager'


// 产品类型管理--------------------------


/**
 * 产品状态格式化
 * @returns  产品状态,0保内，1保外
 */
export function formatDeviceStatus(deviceStatus) {
  var deviceStatusName = ''
  switch (deviceStatus) {
      case 0:
        deviceStatusName = '保内'
        break
      case 1:
        deviceStatusName = '保外'
        break
      default:
        deviceStatusName = '-'
        break
  }
  return deviceStatusName
}


/**
 * 售出状态格式化
 * @returns  产品售出状态，1在库，2售出，3维修中
 */
export function formatDeviceSoldStatus(deviceSoldStatus) {
  var deviceSoldStatusName = ''
  switch (deviceSoldStatus) {
      case 1:
        deviceSoldStatusName = '在库'
        break
      case 2:
        deviceSoldStatusName = '售出'
        break
      case 3:
        deviceSoldStatusName = '维修中'
        break
      default:
        deviceSoldStatusName = '-'
        break
  }
  return deviceSoldStatusName
}

/**
 * 性别
 * @param {*} sex 
 * @returns  性别：1男 2女
 */
export function transferSex(sex) {
  var sexName = ''
  switch (sex) {
      case '1':
          sexName = '男'
          break
      case '2':
          sexName = '女'
          break
      default:
          sexName = '-'
          break
  }
  return sexName
}
/**
 * 获取产品类型列表
 * @param {*} paramIo 
 */
export function getDeviceTypeList(paramIo) {
  return axios({
    url: '/api/backend/device-types/search',
    method: 'post',
    data: paramIo
  })
}

/**
 * 添加产品类型
 * @param {*} paramIo 
 */
export function addDeviceType(paramIo) {
  return axios({
    url: '/api/backend/device-types/create',
    method: 'post',
    data: paramIo
  })
}

/**
 * 修改产品类型
 * @param {*} paramIo 
 */
export function updateDeviceType(deviceTypeId,paramIo) {
  //主键ID
  paramIo.deviceTypeId = deviceTypeId
  return axios({
    url: '/api/backend/device-types/update',
    method: 'post',
    data: paramIo
  })
}

/**
 * 删除产品类型
 * @param {*} paramIo 
 */
export function deleteDeviceType(deviceTypeId) {
  return axios({
    url: '/api/backend/device-types/delete/'+deviceTypeId,
    method: 'post'
  })
}


// 产品类型管理--------------------------



// 产品档案--------------------------
/**
 * 获取device产品列表
 * @param {*} paramIo 
 */
export function getDeviceList(paramIo) {
    return axios({
      url: '/api/backend/devices/search',
      method: 'post',
      data: paramIo
    })
}


/**
 * 添加产品
 * @param {*} paramIo 
 */
export function addDevice(paramIo) {
  //自动+1天
  //paramIo.manufactureDate = new Date(paramIo.manufactureDate.setDate(paramIo.manufactureDate.getDate() + 1));
  return axios({
    url: '/api/backend/devices/create',
    method: 'post',
    data: paramIo
  })
}

/**
 * 产品入库
 * @param {*} paramIo 
 */
export function deviceIn(paramIo) {
  return axios({
    url: '/api/backend/devices/device-in',
    method: 'post',
    data: paramIo
  })
}

/**
 * 产品出库
 * @param {*} paramIo 
 */
export function deviceOut(paramIo) {
  return axios({
    url: '/api/backend/devices/device-out',
    method: 'post',
    data: paramIo
  })
}

/**
 * 更新产品
 * @param {*} paramIo 
 */
export function updateDevice(deviceId,paramIo) {
  //自动+1天
  //paramIo.manufactureDate = new Date(paramIo.manufactureDate.setDate(paramIo.manufactureDate.getDate() + 1));
  //主键ID
  paramIo.deviceId = deviceId
  return axios({
    url: '/api/backend/devices/update',
    method: 'post',
    data: paramIo
  })
}

/**
 * 删除产品
 * @param {*} paramIo 
 */
export function deleteDevice(deviceId) {
  return axios({
    url: '/api/backend/devices/delete/'+deviceId,
    method: 'post'
  })
}
/**
 * 上传批量设备文件
 * @param {*} paramIo 
 */
export function updateDeviceFile(paramIo) {
  return axios({
    url: '/api/backend/devices/upload',
    method: 'post',
    data: paramIo,
    headers: {
      'Content-Type':'multipart/form-data'
    },
    timeout: 3000000
  })
}

/**
 * 解析批量设备文件
 * @param {*} paramIo 
 */
export function deviceBatchCreate(paramIo) {
  return axios({
    url: '/api/backend/devices/batch',
    method: 'post',
    data: paramIo
  })
}

// 产品档案--------------------------



// 设备零件管理--------------------------
/**
 * 获取设备零件列表
 * @param {*} paramIo 
 */
export function getDevicePartList(paramIo) {
  return axios({
    url: '/api/backend/device-parts/search',
    method: 'post',
    data: paramIo
  })
}


/**
 * 添加设备零件
 * @param {*} paramIo 
 */
export function addDevicePart(paramIo) {
  return axios({
    url: '/api/backend/device-parts/create',
    method: 'post',
    data: paramIo
  })
}


/**
 * 设备零件入库
 * @param {*} paramIo 
 */
export function partIn(paramIo) {
  return axios({
    url: '/api/backend/device-parts/part-in',
    method: 'post',
    data: paramIo
  })
}

/**
 * 设备零件出库
 * @param {*} paramIo 
 */
export function partOut(paramIo) {
  return axios({
    url: '/api/backend/device-parts/part-out',
    method: 'post',
    data: paramIo
  })
}

/**
 * 修改设备零件
 * @param {*} paramIo 
 */
export function updateDevicePart(partId,paramIo) {
  //主键ID
  paramIo.partId = partId
  return axios({
    url: '/api/backend/device-parts/update',
    method: 'post',
    data: paramIo
  })
}

/**
 * 删除设备零件
 * @param {*} paramIo 
 */
export function deleteDevicePart(partId) {
  return axios({
    url: '/api/backend/device-parts/delete/'+partId,
    method: 'post'
  })
}

// 设备零件管理--------------------------

// 出入库记录管理--------------------------

export function getDeviceRecordList(paramIo) {
  let finalUrl = joinPramas("/api/backend/deviceRecords/search", paramIo)
  return axios({
    url: finalUrl,
    method: 'get'
  })
}

// 出入库记录管理--------------------------


// 资料库--------------------------
/**
 * 文件类型
 * @param {*} fileType 
 * @returns  文件类型；0：图片；1：pdf；2：word
 */
export function transferFileType(fileType) {
  var fileTypeName = ''
  switch (fileType) {
      case '0':
        fileTypeName = '图片'
          break
      case '1':
        fileTypeName = 'PDF'
          break
      case '2':
        fileTypeName = 'Word'
          break
      default:
        fileTypeName = '-'
          break
  }
  return fileTypeName
}


/**
 * 获取资料库列表
 * @param {*} paramIo 
 */
export function getInfoLibraryList(paramIo) {
  let finalUrl = joinPramas("/api/backend/infoLib/list", paramIo)
  return axios({
    url: finalUrl,
    method: 'get'
  })
}


/**
 * 添加资料
 * @param {*} paramIo 
 */
export function addInfoLibrary(paramIo) {
  return axios({
    url: '/api/backend/infoLib/add',
    method: 'post',
    data: paramIo,
    headers: {
      'Content-Type':'multipart/form-data'
    },
    timeout: 3000000
  })
}

/**
 * 修改资料
 * @param {*} paramIo 
 */
export function editInfoLibrary(id,paramIo) {
  paramIo.id = id
  return axios({
    url: '/api/backend/infoLib/edit',
    method: 'post',
    data: paramIo
  })
}

/**
 * 删除资料
 * @param {*} paramIo 
 */
export function deleteInfoLibrary(id) {
  return axios({
    url: '/api/backend/infoLib/delete/'+id,
    method: 'post'
  })
}

/**
 * 上架|下架资料
 * @param {*} paramIo 
 */
export function updateInfoLibState(id,state) {
  return axios({
    url: '/api/backend/infoLib/changeState/'+id + "/"+state,
    method: 'post'
  })
}


/**
 * 获取下载地址
 * @param {*} paramIo 
 */
export function downloadInfoLibFile(id) {
  return axios({
    url: '/api/backend/infoLib/getFiles/'+id,
    method: 'post'
  })
}
// 资料库--------------------------


// 船舶管理------------------------
export function shipList(paramIo) {
  return axios({
    url: '/api/backend/ship/list',
    data: paramIo,
    method: 'post'
  })
}
export function addShip(paramIo) {
  return axios({
    url: '/api/backend/ship/add',
    data: paramIo,
    method: 'post'
  })
}
export function updateShip(id,paramIo) {
  paramIo.id = id
  return axios({
    url: '/api/backend/ship/update',
    data: paramIo,
    method: 'post'
  })
}
export function deleteShip(id) {
  return axios({
    url: '/api/backend/ship/delete/'+id,
    method: 'post'
  })
}

export function checkNamePrefix(projectName) {
  return axios({
    url: '/api/backend/projects/checkPrefix/'+projectName,
    method: 'post'
  })
}
export function getShipInfo(shipId) {
  return axios({
    url: '/api/backend/ship/getShipInfo?id=' + shipId,
    method: 'post'
  })
}

  export function api_ship_uploadFile(paramIo) {
    return axios({
      url: '/api/backend/ship/upload',
      method: 'post',
      data: paramIo,
      headers: {
        'Content-Type':'multipart/form-data'
      },
      timeout: 3000000
    })
  }
// 船舶管理------------------------


// 工时管理------------------------
export function workHourList(paramIo) {
  return axios({
    url: '/api/backend/work-hour/list',
    data: paramIo,
    method: 'post'
  })
}
// 工时管理------------------------


// 培训管理------------------------
export function searchTrainingsList(paramIo) {
  return axios({
    url: '/api/backend/training/search',
    data: paramIo,
    method: 'post'
  })
}

export function getTrainingById(id) {
  return axios({
    url: '/api/backend/training/getById?trainingId='+id,
    method: 'get'
  })
}

export function getTrainingEvaluation(id) {
  return axios({
    url: '/api/backend/training/getTrainingEvaluation?trainingId='+id,
    method: 'get'
  })
}

export function getTrainingReport(id) {
  return axios({
    url: '/api/backend/training/getTrainingReport?trainId='+id,
    method: 'get'
  })
}
// 培训管理------------------------
